<?php

use Faker\Factory as Faker;
use App\Models\Qrcode;
use App\Repositories\QrcodeRepository;

trait MakeQrcodeTrait
{
    /**
     * Create fake instance of Qrcode and save it in database
     *
     * @param array $qrcodeFields
     * @return Qrcode
     */
    public function makeQrcode($qrcodeFields = [])
    {
        /** @var QrcodeRepository $qrcodeRepo */
        $qrcodeRepo = App::make(QrcodeRepository::class);
        $theme = $this->fakeQrcodeData($qrcodeFields);
        return $qrcodeRepo->create($theme);
    }

    /**
     * Get fake instance of Qrcode
     *
     * @param array $qrcodeFields
     * @return Qrcode
     */
    public function fakeQrcode($qrcodeFields = [])
    {
        return new Qrcode($this->fakeQrcodeData($qrcodeFields));
    }

    /**
     * Get fake data of Qrcode
     *
     * @param array $postFields
     * @return array
     */
    public function fakeQrcodeData($qrcodeFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'shop_id' => $fake->randomDigitNotNull,
            'type' => $fake->randomDigitNotNull,
            'url' => $fake->text,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $qrcodeFields);
    }
}
